<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">内部用户计算任务</ui:define>
    <ui:define name="content">
        <h:form>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar id="buttonToolBar">
                    <f:facet name="right">
                        <p:commandButton value="发送" icon="fa fa-bullhorn"
                                         action="#{smsConditionViewBean.onSend}"
                                         rendered="#{smsConditionViewBean.smsCalculateTask.status.ordinal() == 2 and smsConditionViewBean.activeIndex == 0}">
                            <f:setPropertyActionListener
                                    value="/views/family/user-info/send-sms/sms-calculate-task.xhtml"
                                    target="#{currentUserBean.back}"/>
                        </p:commandButton>
                        <p:commandButton value="重新发送" icon="fa fa-repeat"
                                         actionListener="#{smsConditionViewBean.onResend}"
                                         rendered="#{smsConditionViewBean.smsSendTask.status.ordinal() == 3 and smsConditionViewBean.activeIndex == 1}"
                                         update="@form"/>
                        <p:commandButton value="恢复发送" icon="fa fa-repeat"
                                         actionListener="#{smsConditionViewBean.onResend}"
                                         rendered="#{smsConditionViewBean.smsSendTask.status.ordinal() == 4 and smsConditionViewBean.activeIndex == 1}"
                                         process="@this"
                                         update="@form"/>
                        <p:commandButton value="保存" icon="fa fa-save"
                                         actionListener="#{smsConditionViewBean.onSaveCalculateTask}"
                                         rendered="#{smsConditionViewBean.canEditCalculateTask() and smsConditionViewBean.activeIndex == 0}"
                                         update="@form"/>
                        <p:commandButton value="保存" icon="fa fa-save"
                                         actionListener="#{smsConditionViewBean.onSaveSendTask}"
                                         rendered="#{smsConditionViewBean.canEditSendTask() and smsConditionViewBean.activeIndex == 1}"
                                         update="@form"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"></p:button>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <p:tabView scrollable="true" style="padding-top: 20px;background: #edf0f5;"
                           activeIndex="#{smsConditionViewBean.activeIndex}">
                    <p:ajax event="tabChange" update="@form"/>
                    <p:tab title="计算任务"
                           rendered="#{smsConditionViewBean.smsCalculateTask != null and smsConditionViewBean.smsCondition != null}">
                        <div class="ui-g">
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        <p:outputLabel value="任务名称"/>
                                    </div>
                                    <div class="ui-g-11">
                                        <p:inputText value="#{smsConditionViewBean.smsCondition.name}"
                                                     disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
                                    </div>
                                </div>
                            </div>
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        <p:outputLabel value="登记时间"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:calendar value="#{smsConditionViewBean.smsCondition.recordStartTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"
                                                    disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
                                        <span>—</span>
                                        <p:calendar value="#{smsConditionViewBean.smsCondition.recordEndTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"
                                                    disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="注册时间"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:calendar value="#{smsConditionViewBean.smsCondition.registerStartTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"
                                                    disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
                                        <span>—</span>
                                        <p:calendar value="#{smsConditionViewBean.smsCondition.registerEndTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"
                                                    disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
                                    </div>
                                </div>
                            </div>
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        运营商
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectManyButton
                                                value="#{smsConditionViewBean.smsCondition.telecomOperators}"
                                                disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItem itemLabel="移动" itemValue="0"/>
                                            <f:selectItem itemLabel="联通" itemValue="1"/>
                                            <f:selectItem itemLabel="电信" itemValue="2"/>
                                        </p:selectManyButton>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="用户类型"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectManyButton value="#{smsConditionViewBean.smsCondition.userTypes}"
                                                           disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItems
                                                    value="#{smsConditionViewBean.dictionaries[DictionaryCode.SMS_USER_TYPE]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectManyButton>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="平台"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectOneButton value="#{smsConditionViewBean.smsCondition.platform}"
                                                           disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItem itemLabel="苹果" itemValue="ios"/>
                                            <f:selectItem itemLabel="安卓" itemValue="android"/>
                                        </p:selectOneButton>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="地区"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectCheckboxMenu id="province" value="#{smsConditionViewBean.smsCondition.provinces}"
                                        						disabled="#{!smsConditionViewBean.canEditCalculateTask()}"
                                                      		updateLabel="true" multiple="true" filter="true">
                                    			<f:selectItems value="#{smsConditionViewBean.provinces}" />
                           				</p:selectCheckboxMenu>
                                    </div>
                                    
                                </div>
                                
		                         <p:outputPanel id="calculateModePanel">
		                        		<div class="card ui-g-12">
		                        		
		                            <div class="ui-g-1">
		                                <p:outputLabel value="计算模式"/>
		                            </div>
		                            <div class="ui-g-5">
				                        <p:selectOneMenu id="calculateMode" value="#{smsConditionViewBean.smsCondition.calculateMode}"
				                        					disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
								             <f:selectItem itemLabel="立即计算" itemValue="0" />
								             <f:selectItem itemLabel="1次定时计算" itemValue="1" />
								             <f:selectItem itemLabel="多次定时计算" itemValue="2" />
								        </p:selectOneMenu>
				                    </div>
		                            
			                           <p:outputPanel id="calculateTime" rendered="#{smsConditionViewBean.smsCondition.calculateTime != null}">
			                           	 <div class="ui-g-1">
				                                <p:outputLabel value="定时计算时间"/>
			                            </div>
			                            <div class="ui-g-5">
			                                <p:calendar value="#{smsConditionViewBean.smsCondition.calculateTime}"
			                                            styleClass="autoWidthCalendar"
			                                            locale="#{constants:get('LOCALE')}"
			                                            timeZone="#{constants:get('TIME_ZONE')}"
			                                            pattern="#{constants:get('DATETIME_FORMAT')}"
			                                            navigator="true"
			                                            converterMessage="日期格式输入错误! 例子: 2018-04-23 12:00:00"
			                                            disabled="#{!smsConditionViewBean.canEditCalculateTask()}"/>
			                            </div>
			                           </p:outputPanel>
		                            
		                        		</div>
		                        
		                        </p:outputPanel>
                        
		                        <div class="card ui-g-12">
		                            <div class="ui-g-1">
                                        <p:outputLabel value="剔除日期"/>
                                    </div>
                                    <div class="ui-g-6">
                                        <p:selectOneButton value="#{smsConditionViewBean.smsCondition.excludeSendedDay}"
                                                           disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                           <f:selectItems
		                                            value="#{smsConditionViewBean.dictionaries[DictionaryCode.SMS_EXCLUDE_SENDED_DAY]}"
		                                            var="dic"
		                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneButton>
                                    </div>
                                    
                                    <div class="ui-g-1">
		                                <p:outputLabel value="剔除甲方"/>
		                            </div>
		                            <div class="ui-g-4">
		                            		<p:selectCheckboxMenu value="#{smsConditionViewBean.smsCondition.excludeSendedFirstPartyNames}"
		                                                      updateLabel="true" multiple="true" filter="true" 
		                                                      disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
		                                    <f:selectItems value="#{smsConditionViewBean.firstPartyNames}" />
		                           		</p:selectCheckboxMenu>
		                            </div>
		                        </div>

                                <div class="card ui-g-12">
                                    <p:panel header="用户定义" toggleable="true" closable="false"
                                             widgetVar="userDefinitionPanel">
                                        <p:selectOneButton
                                                value="#{smsConditionViewBean.smsCondition.selectedUserDefinitionId}"
                                                disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <p:ajax event="change"
                                                    listener="#{smsConditionViewBean.onSelectUserDefinition}"/>
                                            <f:selectItems value="#{smsConditionViewBean.smsUserDefinitions}"
                                                           var="smsUserDefinition"
                                                           itemLabel="#{smsUserDefinition.name}"
                                                           itemValue="#{smsUserDefinition.id}"/>
                                        </p:selectOneButton>
                                    </p:panel>
                                </div>

                                <div class="card ui-g-12">
                                    <p:panel header="活动类型（多选）" toggleable="true" closable="false"
                                             widgetVar="activityTypePanel">
                                        <p:selectManyButton
                                                value="#{smsConditionViewBean.smsCondition.activityTypes}"
                                                disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItems value="#{smsConditionViewBean.activityTypes}"
                                                           var="type"
                                                           itemLabel="#{type.activityTypeName}"
                                                           itemValue="#{type.activityType}"/>
                                        </p:selectManyButton>
                                    </p:panel>
                                </div>

                                <div class="card ui-g-12">
                                    <p:panel header="产品（多选）" toggleable="true" closable="false"
                                             widgetVar="productPanel">
                                        <p:selectManyButton value="#{smsConditionViewBean.smsCondition.products}"
                                                            disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItems value="#{smsConditionViewBean.commProductIds}" var="product"
                                                           itemValue="#{product.productId}"
                                                           itemLabel="#{product.name}"/>
                                        </p:selectManyButton>
                                    </p:panel>
                                </div>

                                <div class="card ui-g-12">
                                    <p:panel header="渠道（多选）" toggleable="true" closable="false"
                                             widgetVar="channelPanel">
                                        <p:selectManyButton value="#{smsConditionViewBean.smsCondition.channels}"
                                                            disabled="#{!smsConditionViewBean.canEditCalculateTask()}">
                                            <f:selectItems value="#{smsConditionViewBean.commProductChannels}"
                                                           var="channel"
                                                           itemLabel="#{channel.channelName}"
                                                           itemValue="#{channel.channelCode}"/>
                                        </p:selectManyButton>
                                    </p:panel>
                                </div>
                            </div>
                        </div>
                    </p:tab>
                    <p:tab title="发送任务"
                           rendered="#{smsConditionViewBean.smsSendTask != null}">
                        <div class="ui-g">
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        <p:outputLabel value="短信平台"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectOneButton value="#{smsConditionViewBean.smsSendTask.platformChannel}"
                                                           disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <f:selectItems
                                                    value="#{smsConditionViewBean.dictionaries[DictionaryCode.SMS_PLATFORM_CHANNEL]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneButton>
                                    </div>

                                    <div class="ui-g-2">
                                        <p:outputLabel value="计划发送时间"/>
                                    </div>
                                    <div class="ui-g-4">
                                        <p:calendar value="#{smsConditionViewBean.smsSendTask.executeTime}"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATETIME_FORMAT')}"
                                                    readonlyInput="true"
                                                    disabled="#{!smsConditionViewBean.canEditSendTask()}"/>
                                    </div>
                                </div>
                            </div>
                            <div class=" ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-12">
                                        <h3><b>短信内容</b></h3>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="模板类型"/>
                                    </div>
                                    <div class="ui-g-11">
                                        <p:selectOneButton value="#{smsConditionViewBean.selectedTemplateGroup}"
                                                           disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change"
                                                    listener="#{smsConditionViewBean.onSelectSmsTemplateGroup}"
                                                    update="smsTemplateSelect"/>
                                            <f:selectItem itemLabel="不限" itemValue=""/>
                                            <f:selectItems
                                                    value="#{smsConditionViewBean.dictionaries[DictionaryCode.SMS_TEMPLATE_GROUP]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneButton>
                                    </div>
                                    <div class="ui-g-1">短信模板</div>
                                    <div class="ui-g-5">
                                        <p:selectOneMenu id="smsTemplateSelect" value="#{smsConditionViewBean.template}"
                                                         filter="true"
                                                         filterMatchMode="contains"
                                                         disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                            <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                                            <f:selectItems
                                                    value="#{smsConditionViewBean.smsTemplates}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneMenu>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="活动名称"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{smsConditionViewBean.activityName}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-6"/>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量1"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{smsConditionViewBean.var1}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量2"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{smsConditionViewBean.var2}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量3"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{smsConditionViewBean.var3}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量4"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{smsConditionViewBean.var4}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{smsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    
                                    <div class="ui-g-1">
		                                <p:outputLabel value="甲方名称"/>
		                            </div>
		                            <div class="ui-g-5">
		                                <p:inputText value="#{smsConditionViewBean.smsSendTask.firstPartyName}"
                                                     disabled="#{!smsConditionViewBean.canEditSendTask()}">
		                                </p:inputText>
		                            </div>

                                    <div class="ui-g-12">
                                        <div class="ui-g-1">
                                            <p:outputLabel value="短信文案"/>
                                        </div>
                                        <div class="ui-g-11">
                                            <p:inputTextarea id="content"
                                                             value="#{smsConditionViewBean.smsSendTask.content}"
                                                             rows="10"
                                                             counter="display" maxlength="70"
                                                             counterTemplate="剩余 {0} 字, 短信文案字数最大限制为70字"
                                                             disabled="#{!smsConditionViewBean.canEditSendTask()}"/>
                                            <h:outputText id="display"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </p:tab>
                </p:tabView>
            </div>
        </h:form>
    </ui:define>
</ui:composition>